/* 
 * File:   Queue.hpp
 * Author: bd
 *
 * Created on March 27, 2011, 2:50 PM
 */

#ifndef QUEUE_HPP
#define	QUEUE_HPP
#include <queue>
#include <boost/thread.hpp>
#include <boost/shared_ptr.hpp>

template <typename T>
class Queue {
public:
    typedef typename boost::shared_ptr<Queue<T> > QueuePtr;
public:

    Queue() {

    }

    ~Queue() {

    }

    T pop(bool& ind) {
        lock_guard lock(mutex_);
        if (q_.size() == 0) {
            ind = false;
            return T();
        } else {
            ind = true;
            T v = q_.front();
            q_.pop();
            return v;
        }
    }

    void push(T val) {
        lock_guard lock(mutex_);
        q_.push(val);
    }

    size_t size() const {
        return q_.size();
    }

    bool empty() const {
        return q_.empty();
    }

private:
    typedef boost::lock_guard<boost::mutex> lock_guard;
    std::queue<T> q_;
    boost::mutex mutex_;
};

#endif	/* QUEUE_HPP */

